const cloud = require('wx-server-sdk')

cloud.init({
    env:"agriculture-4g9roniha194f9d1"
})
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    var openid = wxContext.OPENID;
    var list = await db.collection('user').where({
        _id:openid
    }).get()

    if(list.data.length == 0){
        return {
            flag:0,
        }
    }else{
        return {
            flag:1,
            user:list.data[0],
        };
    }
}